package com.cxm.report.service.impl;

import com.cxm.report.model.criteria.ReportFilter;
import com.cxm.report.model.data.Report;
import com.cxm.report.model.data.ReportDetail;
import com.cxm.report.util.DateUtil;

import java.util.List;

/**
 * @author scl.BlueOcean
 * @version 1.0
 * @date 2018年09月06 15:41
 * @description
 */
public abstract class AbstractReportService {
    protected void setFirstAndLast(List<Report> reports, ReportFilter filter) {
        //对第一个设置结束时间
        Report firstReport = reports.get(0);
        String[] scope = firstReport.getDate().split("To");
        String end = filter.getEnd();
        String begin = filter.getBegin();
        firstReport.setDate(String.format("%s To %s",scope[0].trim(),end));
        //对最后一个设置开始时间
        if (DateUtil.compare(begin,scope[1].trim())>0){
            Report lastReport = reports.get(reports.size() - 1);
            scope = lastReport.getDate().split("To");
            lastReport.setDate(String.format("%s To %s",begin,scope[1].trim()));
        }
    }

    protected void setRingRatio(ReportDetail brandReport, ReportDetail br) {
        if (br != null){
            int lastOrderNum = br.getOrderNum();
            Double ringRatio = (brandReport.getOrderNum()-lastOrderNum)*100.0/lastOrderNum;
            brandReport.setRingRatio(ringRatio);
        }
    }
}
